<?php
require_once MODULE_PATH .'/cms/link.php';

class C_Product extends C_Abstract
{
    protected $_idx = '';
    
    public function __construct()
    {
        parent::__construct();
        $this->_idx = getRequest('idx', '', 'stringTrim');
        $this->smt->assign('idx', $this->_idx);
    }


    public function indexAction()
    {
        require_once MODULE_PATH .'/cms/cmsclass.php';
        $idxs = \Modules\Cms\Cmsclass::fetchList('product');
        $num = 9;
        
        $kw = getGet('kw', '', 'stringTrim');
        if ($kw) {
            $list = \Modules\Cms\Link::search($kw, 'product', $this->_idx, $num, $this->_page);
            $title = '关键词：'. $kw;
        } else {
            $list = \Modules\Cms\Link::fetch('product', $this->_idx, $num, $this->_page);
            $title = $idxs[$this->_idx]['cname'];
        }

        $this->smt->assign('list', $list);
        $this->smt->assign('idxs', $idxs);
        $this->smt->assign('title', $title);
        $this->smt->assignByRef('pages', \Modules\Cms\Link::getPages($this->_page, $num));
        $this->smt->assign('page_url', '\?c=product&idx='. $this->_idx .'&kw='. $kw .'&');
        $this->smt->display('product.html');
    }
    
    public function showAction()
    {
        $id = getGet('id', 0, 'int');
        if (!$id || false == ($data = \Modules\Cms\Link::fetchOne($id))) {
            \SF\Controller\Router::redirect('/?c=product');
        }
        
        $this->smt->assign('data', $data);
        $this->smt->display('product_show.html');
    }
}